<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阿C记事本</title>
    <!-- <link rel="stylesheet" href="css/ac.css"> -->
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        button {
            margin: 0;
            padding: 0;
            border: 0;
            background: none;
            font-size: 100%;
            vertical-align: baseline;
            font-family: inherit;
            font-weight: inherit;
            color: inherit;
            outline: none;
        }
        
        body {
            background-color: whitesmoke;
            color: #4d4d4d;
            font-weight: 100;
        }
        
        li {
            list-style: none;
        }
        
        .header h1 {
            position: absolute;
            top: 20px;
            text-align: center;
            width: 100%;
            font-size: 60px;
            color: rgba(175, 47, 47, .8);
            font-weight: inherit;
        }
        
        .header input,
        .todo,
        .footer {
            position: absolute;
            top: 150px;
            left: 50%;
            margin-left: -275px;
            border: 0;
            position: relative;
            font-size: 24px;
            font-family: inherit;
            font-weight: inherit;
            line-height: 65px;
            color: inherit;
            padding: 0px 16px;
            /* border: 1px solid #999; */
            box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.2);
            box-sizing: border-box;
            outline-color: #999;
            width: 550px;
            height: 65px;
            background-color: white;
            /* -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale; */
            /* box-shadow: rgba(0, 0, 0, 0.5); */
        }
        
        .header input {
            margin-bottom: 1px;
        }
        
        input::-webkit-input-placeholder {
            color: #999;
        }
        
        .todo-list .view .index {
            color: gray;
            left: 10px;
            top: 20px;
            font-size: 16px;
            font-weight: 400;
            padding-right: 30px;
        }
        
        .todo-list li .destroy {
            display: none;
            float: right;
            /* right: 10px; */
            width: 40px;
            height: 40px;
            margin: auto 0;
            font-size: 30px;
            color: #cc9a9a;
            line-height: 65px;
        }
        
        .todo-list li:hover .destroy {
            display: block;
        }
        
        .todo-list li .destroy:hover {
            color: #af5b5e;
        }
        
        .todo-list li .destroy:after {
            content: "×";
        }
        
        .footer {
            font-size: 14px;
            width: 550px;
            height: 40px;
            line-height: 40px;
        }
        
        .footer strong {
            font-weight: 300;
        }
        
        .clear,
        .clear:active {
            float: right;
            position: relative;
            line-height: 40px;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <section id="todoIt">
        <header class="header">
            <h1>阿C记事本</h1>
            <input type="text" placeholder="请输入任务" v-model="inputValue" autofocus="autofocus" @keyup.enter="add"></div>
        </header>

        <section class="main">
            <ul class="todo-list">
                <li class="todo" v-for="(item,index) in arr">
                    <div class="view"><span class="index">{{ index+1 }}.</span>
                        <label>{{ item }}</label>
                        <button class="destroy" @click="destroy(index)"></button>
                    </div>
                </li>
            </ul>
        </section>
        <!-- 统计和清空 -->
        <footer class="footer" v-show="arr.length>0">
            <span class="todo-count">
                <strong>{{ arr.length }}</strong> items left
            </span>
            <button class="clear" @click="clearAll">
                Clear
            </button>
        </footer>
    </section>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var todo = new Vue({
            el: "#todoIt",
            data: {
                arr: ["吃饭", "睡觉", "打代码"],
                inputValue: "好好学习,天天向上"
            },

            methods: {

                // 功能1:新增
                // 1.生成列表结构
                // 2.获取用户输入
                // 3.通过回车新增数据
                add: function() {
                    if (this.inputValue != '') {
                        this.arr.push(this.inputValue);
                        this.inputValue = '';
                    } else {
                        alert('内容不能为空噢')
                    }
                },
                // 功能2:删除
                // 1.点击按钮
                // 2.用splice删除(数组删除)
                destroy: function(index) {
                    console.log(index);
                    this.arr.splice(index, 1);
                },
                // 功能3:清空
                clearAll: function() {
                    var clear = confirm('确定清空吗');

                    if (clear) {
                        this.arr = [];
                    }
                }
            }
        })
    </script>



</body>

</html>